﻿{include file='pub/header'/}
<title>订单列表</title>
</head>

<body class="pos-r">
<nav class="breadcrumb">{$breadNav} <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                       href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div class="text-c">
            <form action="{:url('index')}" method="get">
                查询类型：
                <select name="searchKey" style="width:auto" class="select">
                    <option value="">未选择</option>
                    <option value="order_no">订单编号</option>
                    <option value="receive_name">收货人姓名</option>
                </select>
                查询条件：
                <input type="text" name="searchValue" value="{$param.searchValue||default=''}" style="width:250px" class="input-text"/>
                订单状态：
                <select name="order_status" style="width: auto;" class="select">
                    <option value="">全部</option>
                    {foreach :config("order_status") as $key=>$val}
                    <option value="{$key}">{$val}</option>
                    {/foreach}
                </select>
                订单生成时间：
                <input type="text" onfocus="WdatePicker({maxDate:'#F{ $dp.$D(datemax)}'})" id="datemin"
                       name="start_time" value="{$param.start_time||default=''}" class="input-text Wdate" style="width:120px;">-
                <input type="text" onfocus="WdatePicker({minDate:'#F{ $dp.$D(datemin)}'})" id="datemax"
                       name="end_time" value="{$param.end_time||default=''}" class="input-text Wdate" style="width:120px;">
                <button class="btn btn-success" type="submit">
                    <i class="Hui-iconfont">&#xe665;</i>查询
                </button>
            </form>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a class="btn btn-primary radius" onclick="downloadOrder()" href="javascript:;">
                    <i class="Hui-iconfont">&#xe640;</i> 下载订单
                </a>
            </span>

        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                <tr class="text-c">
                    <th width="60">订单编号</th>
                    <th width="60">下单时间</th>
                    <th width="60">下单会员</th>
                    <th width="30">订单状态</th>
                    <th width="30">配送状态</th>
                    <th width="30">支付方式</th>
                    <th width="30">订单总金额</th>
                    <th width="60">支付总金额</th>
                    <th width="60">配送方式</th>
                    <th width="60">预计配送/到店自提时间</th>
                    <th width="60">实际配送/到店自提时间</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                {foreach $list as $item}
                <tr class="text-c va-m">
                    <td>{$item.order_no}</td>
                    <td>{$item.create_time}</td>
                    <td>{$item.username}</td>
                    <td>
                        {if $item.is_apply_refund == 0}
                        {:config('order_status')[$item.order_status]}
                        {elseif $item.is_apply_refund == 1/}
                        申请退款
                        {elseif $item.is_apply_refund == 2/}
                        已退款
                        {elseif $item.is_apply_refund == 3/}
                        已拒绝退款，{:config('order_status')[$item.order_status]}
                        {/if}
                    </td>
                    <td class="is_send">
                        {if $item.is_send == 0}
                        未配送
                        {else/}
                        已配送
                        {/if}
                    </td>
                    <td>{:config('pay_type')[$item.pay_type]}</td>
                    <td>{$item.shop_cost}</td>
                    <td>{$item.real_cost}</td>
                    <td class="text-c">
                        {if $item.dispatch_type == 0}
                        店铺配送
                        {else/}
                        到店自提
                        {/if}
                    </td>
                    <td>{$item.dispatch_time}</td>
                    <td>{$item.send_time}</td>
                    <td class="td-manage">
                        <a style="text-decoration:none" class="ml-5" onClick="order_detail('{$item.id}')"
                           href="javascript:;" title="订单详情">
                            <i class="Hui-iconfont">&#xe623;</i>订单详情
                        </a>
                        <a style="text-decoration:none" class="ml-5"
                           href="{:url('order_print', ['order_id'=>$item.id])}" target="_blank" title="打印小票">
                            <i class="Hui-iconfont">&#xe623;</i>打印小票
                        </a>

                        {if ($item.pay_status == 1 && $item.is_apply_refund == 0)}
                        <a href="javascript:;" class="ml-5" style="text-decoration: none;"
                           onclick="refund_order('{$item.order_no}')"><i class="Hui-iconfont Hui-iconfont-edit"></i>商品退货处理</a>
                        {/if}

                        {if $item.is_send != 1 && $item.is_apply_refund == 0 && $item.pay_status==1}
                        <a style="text-decoration:none" class="ml-5" onClick="send(this,'{$item.id}')"
                           href="javascript:;">
                            <i class="Hui-iconfont">&#xe623;</i>待配送
                        </a>
                        {/if}
                        {if $item.is_send == 1 && time() gt strtotime($item.send_time)+60*60 && $item.order_status == 1}
                        <a style="text-decoration:none" class="ml-5" onClick="sure_order(this,'{$item.id}')"
                           href="javascript:;" title="确认收获">
                            <i class="Hui-iconfont">&#xe6a7;</i>确认收获
                        </a>
                        {/if}
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
            {$list->render()}
        </div>
    </div>

{include file='pub/footer'/}
<script type="text/javascript">
    // $('.table-sort').dataTable({
    //     "aaSorting": [[1, "desc"]],//默认第几个排序
    //     "bStateSave": false,//状态保存
    //     "aoColumnDefs": [
    //         {"orderable": false, "aTargets": [8]}// 制定列不参与排序
    //     ],
    // });

    var params = '{:json_encode($param)}';
    params = JSON.parse(params);
    $(function () {
        let search_key  = $("select[name='searchKey']");
        let list = search_key.find("option");
        $.each(list, function (i,v) {
            if($(v).val() == params.searchKey){
                $(v).attr("selected", "selected");
            }
        });

        let order_status = $("select[name='order_status']");
        let list2 = order_status.find("option");
        $.each(list2, function (i,v) {
            if($(v).val() == params.order_status){
                $(v).attr("selected", "selected");
            }
        });

    });

    function refund_order(order_id) {
        layer_show('订单商品', "{:url('Order/refund_goods')}?order_id=" + order_id);
    }

    //下载订单
    function downloadOrder() {
        layer_show('下载订单', "{:url('Order/downloadOrder')}", '350', '300');
    }

    //订单详情
    function order_detail(order_id) {
        layer_show('订单详情', "{:url('Order/order_detail')}?order_id=" + order_id);

    }

    //订单配送
    function send(o, order_id) {
        layer.confirm('确认配送订单？', function () {
            $.post("{:url('send_order')}", {'order_id': order_id}, function (res) {
                if (res.code == 1) {
                    $(o).parent().siblings('.is_send').html("已配送");
                    $(o).remove();
                }
                layer.msg(res.msg);
            });
        });
    }

    //确认收获
    function sure_order(o, order_id) {
        layer.confirm("确认收获？", function () {
            $.post("{:url('sure_order')}", {'order_id': order_id}, function (res) {
                if (res.code == 1) {
                    location.reload();
                } else {
                    layer.msg(res.msg);
                }

            });
        });

    }

</script>
</body>
</html>